package Cy.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Cy.DAO.OrderDAO;
import Entity.Commodity;
import Entity.Selectorders;
import Entity.Users;
import Factory.OrderFactory;

/**
 * Servlet implementation class SelectorderServlet
 */
@WebServlet("/selectorderzhongzhuan")
public class SelectorderzhongzhuanServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private OrderDAO orderDAO = OrderFactory.createDAO();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int curpage = Integer.parseInt(request.getParameter("curpage"));
		int pagesize = Integer.parseInt(request.getParameter("pagesize"));
		List<Users> userlist = orderDAO.selectuser();
		List<Commodity> comlist = orderDAO.selectcom();
		int cid = Integer.parseInt(request.getParameter("cid"));
		if(cid!=0){
			List<Selectorders> list = orderDAO.selectordercom(cid, curpage, pagesize);
			int total = orderDAO.countorderscom(cid);
			request.setAttribute("list", list);
			request.setAttribute("total", total);
			request.setAttribute("cid", cid);
		}else{
			int uid = Integer.parseInt(request.getParameter("uid"));
			if(uid!=0){
				List<Selectorders> list = orderDAO.selectorderuser(uid, curpage, pagesize);
				int total = orderDAO.countordersuser(uid);
				request.setAttribute("list", list);
				request.setAttribute("total", total);
				request.setAttribute("uid", uid);
			}
			List<Selectorders> list = orderDAO.selectorder(curpage, pagesize);
			int total = orderDAO.countorders();
			request.setAttribute("list", list);
			request.setAttribute("total", total);
		}
		request.setAttribute("userlist", userlist);
		request.setAttribute("comlist", comlist);
		request.getRequestDispatcher("selectOrderszhongzhuan.jsp?curpage="+curpage+"&pagesize").forward(request, response);
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
}
